# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
# The following only applies to changes made to this file as part of YugaByte development.
#
# Portions Copyright (c) YugaByte, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.  You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied.  See the License for the specific language governing permissions and limitations
# under the License.
#

set(CLIENT_SRCS
  async_initializer.cc
  async_rpc.cc
  batcher.cc
  client.cc
  client_builder-internal.cc
  client-internal.cc
  error_collector.cc
  error-internal.cc
  in_flight_op.cc
  meta_cache.cc
  session-internal.cc
  schema.cc
  table-internal.cc
  table_alterer-internal.cc
  table_creator-internal.cc
  table_handle.cc
  tablet_server-internal.cc
  tablet_rpc.cc
  transaction.cc
  transaction_manager.cc
  transaction_rpc.cc
  value.cc
  yb_op.cc
  yb_table_name.cc
)

set(CLIENT_LIBS
  yb_common
  master_proto
  master_rpc
  master_util
  server_process
  tserver_proto
  tserver_service_proto
  tserver_util
  yb_util
  gutil
  yrpc)

# We customize the output name/directory of the exported library so that we can
# call it "yb_client" without it colliding with the regular library.
#
# Unfortunately, this doesn't extend to the autogenerated cmake files that ship
# with the exported library; they still hew to the original target name of
# "yb_client_exported".
ADD_YB_LIBRARY(yb_client
  SRCS ${CLIENT_SRCS}
  DEPS ${CLIENT_LIBS})

if(NOT APPLE)
  # Localize thirdparty symbols using a linker version script. This hides them
  # from the client application. The OS X linker does not support the
  # version-script option.
  set(LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/symbols.map")
endif()

# Test utility library

# This code is useful for other tests which use the client, but isn't
# part of the client itself (ie we don't want to ship it to customers,
# and therefore don't need to worry about export strictness)
add_library(yb_client_test_util
            client-test-util.cc)
target_link_libraries(yb_client_test_util
                      gmock
                      yb_client)

add_library(ql-dml-test-base ql-dml-test-base.cc)
target_link_libraries(ql-dml-test-base integration-tests)

# Tests

set(YB_TEST_LINK_LIBS yb_client ql_util integration-tests ql-dml-test-base ${YB_MIN_TEST_LIBS})
ADD_YB_TEST(client-test)
ADD_YB_TEST(client-unittest)
ADD_YB_TEST(ql-dml-test)
ADD_YB_TEST(ql-dml-ttl-test)
ADD_YB_TEST(ql-tablet-test)
ADD_YB_TEST(ql-transaction-test)
